package com.marcandjo.gwtproject.client;

import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.marcandjo.gwtproject.client.model.Photo;

public class PhotoWidget extends Composite
{
	public PhotoWidget(Photo photo)
	{
		createUi(photo);
	}

	private void createUi(Photo photo)
	{
        FlowPanel widget = new HorizontalFlowPanel();
        initWidget(widget);

		CaptionPanel panel = new CaptionPanel();
		
		panel.setCaptionText(photo.getId());
		panel.add(createBody(photo));

		widget.add(panel);
	}
	
	private FlowPanel createBody(Photo photo)
	{
		FlowPanel panel = new FlowPanel();

		Image img = new Image(photo.getUrl());
		img.setPixelSize(250, 200);
		
		panel.add(new Label(photo.getDescription()));
		panel.add(img);
		
		return panel;
	}
}
